<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表过滤-计算属性实现</title>
    <script src="../vue.js"></script>
</head>

<body>
    <!-- 
        v-for指令：
            1、用于展示列表
            2、语法：v-for="(item,index) in xxx" :key="index/yyy"
            3、可遍历：数组、对象、字符串、指定次数
     -->

    <div id="root">
        <h2>人员列表（过滤列表）</h2>
        <input type="text" placeholder="请输入名字" v-model="keyword">
        <ul>
            <li v-for="(man,index) in filterMans" :key="man.id">{{man.name}}-{{man.age}}-{{man.sex}}</li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip=false;
        new Vue({ 
            el: '#root',
            data: {
                keyword:'',
                mans:[
                    {
                        id:001,
                        name:"张三丰",
                        age:"18",
                        sex:"男"
                    },
                    {
                        id:002,
                        name:"张无忌",
                        age:"20",
                        sex:"男"
                    },
                    {
                        id:003,
                        name:"花无缺",
                        age:"19",
                        sex:"男"
                    },
                    {
                        id:004,
                        name:"花灵龙",
                        age:"18",
                        sex:"男"
                    },
                    {
                        id:005,
                        name:"李小龙",
                        age:"33",
                        sex:"男"
                    },
                    {
                        id:006,
                        name:"马冬梅",
                        age:"24",
                        sex:"女"
                    },
                    {
                        id:007,
                        name:"周冬雨",
                        age:"21",
                        sex:"女"
                    },
                    {
                        id:'008',
                        name:"张碧城",
                        age:"26",
                        sex:"女"
                    },
                ],
            },
            computed:{
                filterMans(){
                   return this.mans.filter((man)=>{
                        return man.name.indexOf(this.keyword)!==-1
                    })
                }
            }
            
        })
    </script>
</body>

</html>